home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / matrix.lha / Matrix / spiral.C < prev    next >
C/C++ Source or Header  |  1992-03-26  |  1KB  |  52 lines

  1. #include <math.h>
  2. #include <libc.h>
  3. #include <bool.h>
  4. #include <stream.h>
  5. #include <GetOpt.h>
  6.  
  7. int
  8. main (int argc, char **argv)
  9.   {
  10.     int        examples = 0;            // number of examples
  11.     int        verbose  = FALSE;        // verbose reporting off
  12.     long    seedval     = 43;            // random number seed value
  13.     double    turns     = 1.0;            // number of 180 degree turns
  14.     GetOpt    getopt (argc, argv, "e:s:t:v");
  15.  
  16.   int option;
  17.   while ((option = getopt()) != EOF)
  18.     switch (option)
  19.       {
  20.         case 'e':                // number of examples
  21.       examples    = atoi(getopt.optarg);
  22.           break;
  23.         case 's':                // seed value
  24.       seedval    = atoi(getopt.optarg);
  25.           break;
  26.         case 't':                // 180 degree turns
  27.       turns        = atoi(getopt.optarg);
  28.           break;
  29.         case 'v':                // verbose reporting on
  30.       verbose    = TRUE;
  31.           break;
  32.         case '?':
  33.           cerr << "Unrecognized option!\n";
  34.       };
  35.  
  36.     if (verbose)
  37.       cerr    << " seedval = "    << seedval
  38.         << " turns = "        << turns
  39.         << " examples = "    << examples << "\n";
  40.     cout << examples << "\n";            // training set
  41.     srand48(seedval);
  42.     for (int example = 0; example < examples; example++)
  43.       {
  44.     double rho = PI*turns*drand48();
  45.     double phi = PI*turns*drand48();
  46.     cout << form("%20.12e", rho) << form("%20.12e", phi)
  47.          << form("%20.12e",   rho*cos(rho - phi))
  48.          << form("%20.12e\n", rho*sin(rho - phi));
  49.       };
  50.     cout.flush();
  51.   }
  52.